﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using AppCommon;

namespace SyncConfig.Dialog
{
    public partial class ChoicePrimaryColumn : SyncConfig.Dialog.BaseDialog
    {
        public string TableName { get; set; }
        public string OldPrimaryColumn
        {
            get;
            set;
        }
        public string CurrentPrimaryColumn
        {
            get
            {

                string keys = "";

                foreach (DevComponents.AdvTree.Node node in advTreeColumns.CheckedNodes)
                {
                    keys += ";" + node.Text;
                }
                return keys;
            }
        }
        public ChoicePrimaryColumn()
        {
            InitializeComponent();
        }

        private void ChoicePrimaryColumn_Load(object sender, EventArgs e)
        {
            DataTable tblColumns = ADOSyncConfig.GetTableColumn(TableName);
            //advTreeColumns.DataSource = tblColumns;
            //advTreeColumns.DisplayMembers = "Name";
            //advTreeColumns.ValueMember = "Name";
            string[] primaryCols = OldPrimaryColumn.Split(';');
            foreach (DataRow row in tblColumns.Rows)
            {
                DevComponents.AdvTree.Node node = new DevComponents.AdvTree.Node(row["Name"].ToString());

                node.CheckBoxStyle = DevComponents.DotNetBar.eCheckBoxStyle.CheckBox;
                node.CheckBoxVisible = true;
                for (int i = 0; i < primaryCols.Length; i++)
                {
                    if (primaryCols[i].Equals(node.Text, StringComparison.InvariantCultureIgnoreCase))
                        node.Checked = true;
                }

                advTreeColumns.Nodes.Add(node);
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

        private void ChoicePrimaryColumn_Shown(object sender, EventArgs e)
        {
            Text = " Choice Primary Columns [" + TableName + "]";
        }
    }
}
